//
//  HomeController.m
//  ai2ban
//
//  Created by mac book pro on 2018/1/6.
//  Copyright © 2018年 mac book pro. All rights reserved.
//

#import "HomeController.h"
#import "HomeHeadView.h"
#import "HomeJXCell.h"
#import "HomeJDCell.h"
#import "HomeTJCell.h"

@interface HomeController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic,strong)UIButton *leftNavBarBtn;

@end

@implementation HomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initTheNavigationBar];
    
    [self initTheUI];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
- (void)viewWillAppear:(BOOL)animated{
    
    //设置导航栏背景图片为一个空的image，这样就透明了
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"home_top"] forBarMetrics:UIBarMetricsDefault];
    
    //去掉透明后导航栏下边的黑边
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack; //状态栏改为白色
    
}
- (void)viewWillDisappear:(BOOL)animated{
    
    //    如果不想让其他页面的导航栏变为透明 需要重置
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
    
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault; //状态栏改为黑色
}


- (void)initTheNavigationBar {
    
    
    UIButton *leftBtn = [[UIButton alloc] init];
    leftBtn.size = CGSizeMake(35, 17+2+14);
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@""];
    [leftBtn addSubview:imageView];
    
    UILabel *tiplabel = [[UILabel alloc] init];
    tiplabel.frame = CGRectMake(0, imageView.bottom+2, leftBtn.width, 14);
    tiplabel.text = @"扫一扫";
    tiplabel.font = [UIFont systemFontOfSize:9];
    tiplabel.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
    tiplabel.textAlignment = NSTextAlignmentCenter;
    [leftBtn addSubview:tiplabel];
    
    
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 26+8, 26)];
    UIImageView *passView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 1, 24, 24)];
    [passView setImage:[UIImage imageNamed:@"home_search"]];
    [leftView addSubview:passView];
    
    UITextField *searchTF = [[UITextField alloc] init];
    searchTF.backgroundColor = COLOR_X(110, 62, 117, 1);
    searchTF.layer.cornerRadius = 29/2.0;
    searchTF.layer.masksToBounds = YES;
    searchTF.leftView = leftView;
    searchTF.leftViewMode = UITextFieldViewModeAlways;
    [searchTF leftViewRectForBounds:CGRectMake(12, 2.5, 14, 14)];
    searchTF.placeholder = @"搜索目的地/景点/酒店等";
    searchTF.font = [UIFont systemFontOfSize:11];
    searchTF.size = CGSizeMake(kScreen_Width, 29);
    
    
}

- (void)initTheUI {
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height-KTabbarHeigth) style:UITableViewStyleGrouped];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.backgroundColor = [UIColor whiteColor];
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:tableView];
    self.tableView = tableView;
    [tableView registerClass:[HomeJXCell class] forCellReuseIdentifier:@"HomeJXCell"];
    [tableView registerClass:[HomeJDCell class] forCellReuseIdentifier:@"HomeJDCell"];
    [tableView registerClass:[HomeTJCell class] forCellReuseIdentifier:@"HomeTJCell"];
    
    HomeHeadView *headView = [[HomeHeadView alloc] init];
    headView.size = CGSizeMake(kScreen_Width, HomeHeadViewHeight);
    tableView.tableHeaderView = headView;
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        HomeJXCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeJXCell" forIndexPath:indexPath];
        
        return cell;
    }
    if (indexPath.section == 1) {
        
        HomeJDCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeJDCell" forIndexPath:indexPath];
        
        return cell;
    }
    
    HomeTJCell*cell = [tableView dequeueReusableCellWithIdentifier:@"HomeTJCell" forIndexPath:indexPath];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        return HomeJXCellHeight;
    }
    if (indexPath.section == 1) {
        return HomeJDCellHeight;
    }
    
    return HomeTJCellHeight;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 8;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *head = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"head"];
    
    if (head == nil) {
        head = [[UIView alloc] init];
        head.backgroundColor = [UIColor groupTableViewBackgroundColor];
        head.size = CGSizeMake(kScreen_Width, 8);
    }
    
    return head;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 0.01;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    UIView *foot = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"foot"];
    
    if (foot == nil) {
        foot = [[UIView alloc] init];
        foot.backgroundColor = [UIColor groupTableViewBackgroundColor];
        foot.size = CGSizeMake(kScreen_Width, 0.01);
    }
    
    return foot;
}





@end
